/**
 * \file  parameter.h
 * \brief Definition of Parameter Template.
 *
 * ASO: Antiviral Sequence Optimizer
 * <http://aso.googlecode.com/>
 * Copyright (C) 2010 Velez Ezequiel, Peralta Andres, FuDePAN
 *
 * This file is part of the ASO project.
 *
 * Contents:       Header file for ASO providing  Template Parameter.
 *
 * System:         ASO
 * Language:       C++
 *
 * Author:         Velez Ezequiel, Peralta Andres
 * E-Mail:
 *
 * ASO is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ASO is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ASO.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef PARAMETER_H
#define PARAMETER_H

#include "aso-core/aso_exception.h"
#include "aso-core/user_parameter.h"

//! Template para parametros generico
template<class T>
class Parameter : public UserParameter
{
    const std::string tag;      //! información
    const std::string info;     //! informacion extendida
    T& paramValue;               //! valor

public:
    //! Constructor
    Parameter(const std::string& tag, const std::string& info, T& value)
        : tag(tag), info(info), paramValue(value)
    {}
    virtual const std::string get_tag() const;
    virtual const std::string get_info() const;
    virtual bool set_value(const std::string& value);
};

template<class T>
const std::string Parameter<T>::get_tag() const
{
    return tag;
}

template<class T>
const std::string Parameter<T>::get_info() const
{
    return info;
}

//! setea el valor del parametro
template<class T>
bool Parameter<T>::set_value(const std::string& value)
{
    return mili::from_string(value, paramValue);
}

//! clase ConditionParameter
template<class T>
class ConditionParameter : public Parameter<T>
{};

//! clase RangeParameter
template<class T>
class RangeParameter : public Parameter<T>
{
    const T MIN;
    const T MAX;
public:
    //! Constructor
    RangeParameter(const std::string tag, const std::string info, T& value, const T& min, const T& max)
        : Parameter<T>::Parameter(tag, info, value), MIN(min), MAX(max)
    {}

    bool set_value(const std::string& value) throw(BadValue)
    {
        T aux;
        bool success(mili::from_string(value, aux));
        if (success)
        {
            success = (MIN <= aux && aux < MAX);
            if (success)
                Parameter<T>::set_value(value);
        }
        return success;
    }
};

//! Lista de parametros
typedef std::list<UserParameter*> ParameterList;
#endif


